package kzx;


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = Integer.valueOf(sc.nextLine());
            String[] temps = sc.nextLine().split(" ");

            int[] p = new int[n];

            for (int i = 0; i < n; i++) {
                p[i] = Integer.valueOf(temps[i]) - 1;
            }
            while (true) {
                String[] strings = sc.nextLine().split(" ");
                int flag = Integer.valueOf(strings[0]);
                if (flag == 0) {
                    break;
                }
                StringBuilder str = new StringBuilder(strings[1]);
                int needAppend=n-str.length();
                for (int i = 0; i < needAppend; i++) {
                    str.append(" ");
                }

                char[] chars = str.toString().toCharArray();

                for (int i = 0; i < flag; i++) {
                    char[] temp = new char[chars.length];
                    for (int i1 = 0; i1 < n; i1++) {
                        temp[p[i1]] = chars[i1];
                    }
                    chars = temp;
                }
                System.out.println(new String(chars));
            }

    }
}
/*

3
3 2 1
1 ABC
2 CBA
1 CBA
1 AB
0
 */